<template>
 <div  class="components-container">
        <sweet-modal ref="dialog" class="dialog">
            <h3>{{ title }}</h3>
             <div style=" height:200px; margin:30px 50px">

              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">部门名称</label>
                  <div class="layui-input-inline">
                    <el-input v-model="dptData.JPDPVDNAME"   placeholder="请输入部门名称"></el-input>
                  </div>

                  <label class="layui-form-label">网址</label>
                  <div class="layui-input-inline">
                    <el-input v-model="dptData.JPDLINKHTTP"   placeholder="请输入网址"></el-input>
                  </div>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">联系人</label>
                  <div class="layui-input-inline">
                    <el-input v-model="dptData.JPDLINKPSN"  placeholder="请输入联系人" ></el-input>
                  </div>
                   <label class="layui-form-label">联系电话</label>
                  <div class="layui-input-inline">
                    <el-input  v-model="dptData.JPDLINKTEL"   placeholder="请输入联系人电话"></el-input>
                  </div>
                </div>
              </div>
             </div>

            <div class="layui-form-item btnCenter">
              <el-button @click="closeDialog">取消</el-button>
              <el-button type="primary" @click="submit" :loading="loading">确定</el-button>
            </div>
        </sweet-modal>
<!-- 详情 -->
         <sweet-modal ref="dialogInfo" class="dialog">
              <h3>{{ title }}</h3>
             <div style=" height:200px; margin:30px 50px">

              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">部门名称</label>
                  <div class="layui-input-inline">
                    <el-input v-model="dptData.JPDPVDNAME"  readonly></el-input>
                  </div>

                  <label class="layui-form-label">网址</label>
                  <div class="layui-input-inline">
                    <el-input v-model="dptData.JPDLINKHTTP"   readonly></el-input>
                  </div>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">联系人</label>
                  <div class="layui-input-inline">
                    <el-input v-model="dptData.JPDLINKPSN"  readonly></el-input>
                  </div>
                   <label class="layui-form-label">联系电话</label>
                  <div class="layui-input-inline">
                    <el-input  v-model="dptData.JPDLINKTEL"  readonly></el-input>
                  </div>
                </div>
              </div>
             </div>

            <div class="layui-form-item btnCenter">
              <el-button @click="closeDialog">取消</el-button>
            </div>
         </sweet-modal>
 </div>
</template>

<script>
import sweetModal from "@/components/sweetModal";
import apiBase from "@/api/apiBase.js";
const ADD = "新增";
const INFO = "详情";
export default {
  name: "DepartmentMain",
  data() {
    return {
      title: null,
      loading: false,
      dptData: {}
    };
  },
  methods: {
    //功能操作
    open(order, id) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.title = "新增";

          this.$refs.dialog.open();
          break;

        case INFO:
          this.title = "详情";
          this.dataInfo(id);
          this.$refs.dialogInfo.open();
          break;
     
        default:
      }
    },
    //提交
    submit() {
      switch (this.order) {
        case ADD:
          this.dataAdd();
          break;
        case INFO:
          this.$refs.dialogInfo.close();
          break;
        default:
      }
    },

    //数据重置
    dataRepeat() {
      this.dptData = {};
    },
    //新增提交
    dataAdd() {
      this.loading = true;

      let Data = JSON.parse(JSON.stringify(this.dptData));
      apiBase.DoService(
        Data,
        apiBase.getApiAdress().JointRegConclude.CreateJointDeptInformation ,
        res => {
          this.loading = false;
          this.$refs.dialog.close();

          this.$message({
            type: "success",
            message: "新增成功!"
          });
          this.refreshData();
        },
        res => {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
      );
    },



    //详情
    dataInfo(id) {
      let data = {
        JPDID: id
      };
      apiBase.DoService(data, apiBase.getApiAdress().JointRegConclude.DetailJointDeptInformation, res => {
        this.dptData = res.data.content;
      });
    },
    closeDialog() {
      if (this.order === ADD || this.order === MODIFY)
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    },

    refreshData() {
      this.$emit("refreshData");
    }
  },
  components: {
    sweetModal
  }
};
</script>

<style>

</style>
